package com.uestc.demotriangle;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class MyGLSurfaceView extends GLSurfaceView {

    private static final String TAG = "====GLTest====";

    public MyGLSurfaceView(Context context) {
        super(context);
        setEGLConfigChooser(8, 8, 8, 0, 16, 0);
        setEGLContextClientVersion(3);
        setRenderer(new MyGLRender());
    }

    public MyGLSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private class MyGLRender implements Renderer {

        private GLTestLib lib;

        public MyGLRender() {
            lib = new GLTestLib();
        }

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            lib.native_init();
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
            lib.native_resize(width, height);
        }

        @Override
        public void onDrawFrame(GL10 gl) {
            lib.native_drawFrame();
        }
    }
}
